package matlap.server;

import java.util.List;

import matlap.client.services.teacher.TeacherService;
import matlap.database.dao.DAOFactory;
import matlap.database.dao.TeacherDAO;
import matlap.shared.Teacher;
import matlap.shared.exceptions.MyException;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */

public class TeacherServiceImpl extends RemoteServiceServlet implements
		TeacherService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	DAOFactory df = DAOFactory.getInstance();
	TeacherDAO td = df.getTeacherDAO();

	/**
	 * Turns back the teachers from the people table in a Teacher list.
	 */

	public List<Teacher> getTeachers() {
		return td.getTeachers();
	}

	/**
	 * Turns back the teachers number from the people table.
	 */

	@Override
	public int getTeachersNumber() {
		return td.getTeachersNumber();
	}

	/**
	 * Turns back the teachers name from the people table in a Teacher list.
	 */

	public List<Teacher> selectTeachersName() {

		return td.selectTeachersName();
	}

	/**
	 * Turns back the teachers from the people table in a Teacher list by adding
	 * teachers name.
	 */

	@Override
	public List<Teacher> getTeachersByName(String teachersName) {
		return td.getTeachersByName(teachersName);
	}

	/**
	 * Turns back the teachers username from the people table in a String list.
	 */

	public List<String> getUserNames() {
		return td.getUserNames();
	}

	/**
	 * Deletes teachers from the people table by adding username.
	 */

	public void deleteTeacher(String userName) throws MyException{
		td.deleteTeacher(userName);
	}

	/**
	 * Updates teachers in the people table by adding username, first name, last
	 * name and address.
	 * @throws MyException 
	 */

	public void updateTeacher(String userName, String firstName,
			String lastName, String address, int accept) throws MyException {
		td.updateTeacher(userName, firstName, lastName, address, accept);
	}

	/**
	 * Turns back a teacher from the people table in Teacher by adding username.
	 */

	public Teacher getTeacherByUserName(String userName) {
		return td.getTeacherByUserName(userName);
	}

}
